package com.ruoyi.web.factory;

import com.ruoyi.common.enums.FileTypeEnum;
import com.ruoyi.common.service.impl.DefaultUploadFileService;
import com.ruoyi.common.utils.ApplicationContextUtil;
import com.ruoyi.market.service.oss.IAliYunOssService;
import com.ruoyi.common.service.IUploadFileService;

import java.util.HashMap;
import java.util.Map;

public class UploadFactory {

    private static Map<String, Class<? extends IUploadFileService>> serviceMap = new HashMap<>();
    static {
        serviceMap.put(FileTypeEnum.PRODUCT.getValue(), IAliYunOssService.class);
        serviceMap.put(FileTypeEnum.BILL.getValue(), IAliYunOssService.class);
        serviceMap.put(FileTypeEnum.STORE.getValue(), IAliYunOssService.class);
        serviceMap.put(FileTypeEnum.PRODLOGO.getValue(), IAliYunOssService.class);
    }

    public static IUploadFileService getService(String type){
        if (serviceMap.containsKey(type)){
            Class<? extends IUploadFileService> aClass = serviceMap.get(type);
            return ApplicationContextUtil.getBean(aClass);
        }
        return ApplicationContextUtil.getBean(DefaultUploadFileService.class);
    }
}
